package manager.ikaraoke.adapter;

import java.util.List;

import manager.ikaraoke.R;
import manager.ikaraoke.database.dto.FoodDrinkDto;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class FoodDrinkAdapter extends ArrayAdapter<FoodDrinkDto> {
	private List<FoodDrinkDto> dtos;
	private Context context;
	private int viewResourceId;

	public FoodDrinkAdapter(Context context, int viewResourceId,
			List<FoodDrinkDto> objects) {
		super(context, viewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.dtos = objects;
		this.viewResourceId = viewResourceId;
	}
	

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		if(convertView == null){
			convertView= LayoutInflater.from(context).inflate(R.layout.row_food_drink, null);
			viewHolder = new ViewHolder();
			viewHolder.txtName = (TextView) convertView.findViewById(R.id.txtnameFood_Drink);
			viewHolder.txtCost = (TextView) convertView.findViewById(R.id.txtpriceFood_Drink);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		//update data
		viewHolder.txtName.setText(dtos.get(position).getName());
		viewHolder.txtCost.setText(dtos.get(position).getCost().toString());
		return convertView;
	}
	class ViewHolder{
		TextView txtName;
		TextView txtCost;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dtos.size();
	}

	@Override
	public FoodDrinkDto getItem(int position) {
		// TODO Auto-generated method stub
		return dtos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return dtos.get(position).getId();
	}

}
